home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / nfs / nfswatch4.0 / logfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-01  |  6.1 KB  |  270 lines

  1. #ifndef lint
  2. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/logfile.c,v 4.0 1993/03/01 19:59:00 davy Exp $";
  3. #endif
  4.  
  5. #include "os.h"
  6.  
  7. /*
  8.  * logfile.c - routines for updating log and snapshot files
  9.  *
  10.  * David A. Curry                Jeffrey C. Mogul
  11.  * Purdue University                Digital Equipment Corporation
  12.  * Engineering Computer Network            Western Research Laboratory
  13.  * 1285 Electrical Engineering Building        250 University Avenue
  14.  * West Lafayette, IN 47907-1285        Palo Alto, CA 94301
  15.  * davy@ecn.purdue.edu                mogul@decwrl.dec.com
  16.  *
  17.  * $Log: logfile.c,v $
  18.  * Revision 4.0  1993/03/01  19:59:00  davy
  19.  * NFSWATCH Version 4.0.
  20.  *
  21.  * Revision 3.3  1993/01/16  19:08:59  davy
  22.  * Corrected Jeff's address.
  23.  *
  24.  * Revision 3.2  1993/01/15  19:33:39  davy
  25.  * Miscellaneous cleanups.
  26.  *
  27.  * Revision 3.1  1993/01/13  20:18:17  davy
  28.  * Put in OS-specific define scheme, and merged in Tim Hudson's code for
  29.  * SGI systems (as yet untested).
  30.  *
  31.  * Revision 3.0  1991/01/23  08:23:05  davy
  32.  * NFSWATCH Version 3.0.
  33.  *
  34.  * Revision 1.2  90/08/17  15:47:22  davy
  35.  * NFSWATCH Version 2.0.
  36.  * 
  37.  * Revision 1.1  88/11/29  11:20:34  davy
  38.  * NFSWATCH Release 1.0
  39.  * 
  40.  */
  41. #include <sys/param.h>
  42. #include <sys/time.h>
  43. #include <curses.h>
  44. #include <stdio.h>
  45.  
  46. #include "nfswatch.h"
  47. #include "externs.h"
  48. #include "screen.h"
  49.  
  50. /*
  51.  * snapshot - take a snapshot of the screen.
  52.  */
  53. void
  54. snapshot()
  55. {
  56.     FILE *fp;
  57.     char buffer[BUFSIZ];
  58.     register int x, y;
  59.  
  60.     /*
  61.      * We want to append to the snapshot file.
  62.      */
  63.     if ((fp = fopen(snapshotfile, "a")) == NULL) {
  64.         (void) mvprintw(SCR_PROMPT_Y, SCR_PROMPT_X,
  65.             "could not open \"%s\"", snapshotfile);
  66.         (void) refresh();
  67.         return;
  68.     }
  69.  
  70.     /*
  71.      * For all lines but the last one ...
  72.      */
  73.     for (y = 0; y < LINES - 1; y++) {
  74.         (void) mvprintw(SCR_PROMPT_Y, SCR_PROMPT_X,
  75.             "dumping line %d", y + 1);
  76.         (void) clrtoeol();
  77.         (void) refresh();
  78.  
  79.         /*
  80.          * Search backwards on each line for a non-space.
  81.          * x is the count of significant characters.
  82.          */
  83.         for (x = COLS - 1; x > 0; x--) {
  84.             /*
  85.              *  Non-space found, increment Z and exit loop
  86.              */
  87.             if (curscr->_y[y][x] != ' ') {
  88.                 x++;
  89.                 break;
  90.             }
  91.         }
  92.  
  93.         /*
  94.          * Copy x characters and append a \n and \0 to the
  95.          * string, then output it.
  96.          */
  97.         (void) strncpy(buffer, curscr->_y[y], x);
  98.         buffer[x++] = '\n';
  99.         buffer[x] = '\0';
  100.  
  101.         (void) fputs(buffer, fp);
  102.     }
  103.  
  104.     (void) fputc('\014', fp);
  105.     (void) fclose(fp);
  106.  
  107.     /*
  108.      * Tell them we're done.
  109.      */
  110.     (void) mvprintw(SCR_PROMPT_Y, SCR_PROMPT_X,
  111.         "screen dumped to \"%s\"", snapshotfile );
  112.     (void) refresh();
  113. }
  114.  
  115. /*
  116.  * update_logfile - put out the information to the log file.
  117.  */
  118. void
  119. update_logfile()
  120. {
  121.     char *tstr;
  122.     char *ctime();
  123.     float percent;
  124.     char buf[BUFSIZ];
  125.     struct timeval tv;
  126.     register int i, j, nfstotal;
  127.  
  128.     (void) gettimeofday(&tv, (struct timezone *) 0);
  129.  
  130.     /*
  131.      * Start a log entry.
  132.      */
  133.     (void) fprintf(logfp, "#\n# begin\n#\n");
  134.     (void) fprintf(logfp, "Date: %.24s\n", ctime(&tv.tv_sec));
  135.  
  136.     tv.tv_sec -= starttime.tv_sec;
  137.     tstr = prtime(tv.tv_sec);
  138.  
  139.     (void) fprintf(logfp, "Cycle Time: %d\n", cycletime);
  140.     (void) fprintf(logfp, "Elapsed Time: %.8s\n", tstr+11);
  141.  
  142.     /*
  143.      * Print total packet counters.
  144.      */
  145.     (void) fprintf(logfp, "#\n# total packets     %8s %8s %8s\n#\n",
  146.         "network", "to host", "dropped");
  147.     (void) fprintf(logfp, "Interval Packets:   %8d %8d %8d\n",
  148.         int_pkt_total, int_dst_pkt_total, int_pkt_drops);
  149.     (void) fprintf(logfp, "Total Packets:      %8d %8d %8d\n",
  150.         pkt_total, dst_pkt_total, pkt_drops);
  151.  
  152.     /*
  153.      * Put out a header for the packet counters.
  154.      */
  155.     (void) fprintf(logfp, "#\n# packet counters         %8s %8s %8s\n#\n",
  156.         "int", "pct", "total");
  157.  
  158.     /*
  159.      * Print the packet counters.  Percentage is calculated as
  160.      * this interval counter over total packets this interval.
  161.      */
  162.     for (i = 0; i < PKT_NCOUNTERS; i++) {
  163.         if (int_dst_pkt_total) {
  164.             percent = ((float) pkt_counters[i].pc_interval /
  165.                   (float) int_dst_pkt_total) * 100.0;
  166.         }
  167.         else {
  168.             percent = 0.0;
  169.         }
  170.  
  171.         (void) sprintf(buf, "%s:", pkt_counters[i].pc_name);
  172.         (void) fprintf(logfp, "%-25s %8d %7.0f%% %8d\n",
  173.             buf, pkt_counters[i].pc_interval, percent,
  174.             pkt_counters[i].pc_total);
  175.     }
  176.  
  177.     /*
  178.      * Calculate the total number of NFS packets this
  179.      * interval.
  180.      */
  181.     nfstotal = pkt_counters[PKT_NFSWRITE].pc_interval +
  182.            pkt_counters[PKT_NFSREAD].pc_interval;
  183.  
  184.     /*
  185.      * Put out a header for the NFS counters.
  186.      */
  187.     (void) fprintf(logfp, "#\n# nfs counters            %8s %8s %8s\n#\n",
  188.         "int", "pct", "total");
  189.  
  190.     /*
  191.      * Print the NFS counters.  Percentage is calculated as
  192.      * packets this interval over total NFS packets this
  193.      * interval.
  194.      */
  195.     for (i = 0; i < nnfscounters; i++) {
  196.         if (nfstotal) {
  197.             percent = ((float) nfs_counters[i].nc_interval /
  198.                   (float) nfstotal) * 100.0;
  199.         }
  200.         else {
  201.             percent = 0.0;
  202.         }
  203.  
  204.         (void) sprintf(buf, "%s:", nfs_counters[i].nc_name);
  205.         (void) fprintf(logfp, "%-25s %8d %7.0f%% %8d\t",
  206.             buf, nfs_counters[i].nc_interval, percent,
  207.             nfs_counters[i].nc_total);
  208.  
  209.         /*
  210.          * Print individual proc counters.
  211.          */
  212.         (void) fputc('(', logfp);
  213.  
  214.         for (j = 0; j < MAXNFSPROC; j++) {
  215.             if (j)
  216.                 (void) fputc('/', logfp);
  217.  
  218.             (void) fprintf(logfp, "%d", nfs_counters[i].nc_proc[j]);
  219.         }
  220.  
  221.         (void) fprintf(logfp, ")\n");
  222.     }
  223.  
  224.     /*
  225.      * Put out a header for the individual file counters.
  226.      */
  227.     (void) fprintf(logfp, "#\n# file counters           %8s %8s %8s\n#\n",
  228.         "int", "pct", "total");
  229.  
  230.     /*
  231.      * Print the individual file counters.  Percentage is
  232.      * calculated as packets this interval over total NFS
  233.      * packets this interval.
  234.      */
  235.     for (i = 0; i < nfilecounters; i++) {
  236.         if (nfstotal) {
  237.             percent = ((float) fil_counters[i].fc_interval /
  238.                   (float) nfstotal) * 100.0;
  239.         }
  240.         else {
  241.             percent = 0.0;
  242.         }
  243.  
  244.         (void) sprintf(buf, "%s:", fil_counters[i].fc_name);
  245.         (void) fprintf(logfp, "%-25s %8d %7.0f%% %8d\t",
  246.             buf, fil_counters[i].fc_interval, percent,
  247.             fil_counters[i].fc_total);
  248.  
  249.         /*
  250.          * Print individual proc counters.
  251.          */
  252.         (void) fputc('(', logfp);
  253.  
  254.         for (j = 0; j < MAXNFSPROC; j++) {
  255.             if (j)
  256.                 (void) fputc('/', logfp);
  257.  
  258.             (void) fprintf(logfp, "%d", fil_counters[i].fc_proc[j]);
  259.         }
  260.  
  261.         (void) fprintf(logfp, ")\n");
  262.     }
  263.  
  264.     /*
  265.      * End the log entry.
  266.      */
  267.     (void) fprintf(logfp, "#\n# end\n#\n");
  268.     (void) fflush(logfp);
  269. }
  270.